

import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:xim/widget/vertical_drag_gesture_detector.dart';

class SimpleSearchWidget extends StatefulWidget {

  SimpleSearchWidget({Key? key, double? width, required this.height}) : super(key: key){
    this.width = width ?? 1.sw;
  }

  late double width;

  final double height;

  @override
  State<SimpleSearchWidget> createState() => _SimpleSearchWidgetState();
}

class _SimpleSearchWidgetState extends State<SimpleSearchWidget> {

  var focusNode = FocusNode();

  var controller = TextEditingController();

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    var outlineInputBorder = OutlineInputBorder(
        borderRadius: BorderRadius.circular(6),
        borderSide: const BorderSide(style: BorderStyle.none)
    );
    return
       Container(
        padding: const EdgeInsets.symmetric(horizontal: 8),
        height: widget.height,
        width: widget.width,
        decoration: const BoxDecoration(
          borderRadius: BorderRadius.all(Radius.circular(8))
        ),
        child: Column(
          children: [
            const SizedBox(height: 8,),
            Row(
              children: [
                Expanded(child: TextField(
                  controller: controller,
                  style: const TextStyle(fontSize: 14),
                  maxLines: 1,
                  focusNode: focusNode,
                  decoration: InputDecoration(
                    isCollapsed: true,
                    fillColor: const Color(0xffF6F6F8),
                    contentPadding: const EdgeInsets.symmetric(vertical: 8, horizontal: 20),
                    filled: true,
                    enabledBorder: outlineInputBorder,
                    focusedBorder: outlineInputBorder,
                    focusedErrorBorder:outlineInputBorder,
                    errorBorder: outlineInputBorder,
                    hintText: "搜索地点",
                    // prefixIcon:const Icon(Icons.search, color: Color(0xffc8d6e5), size: 14,),
                    suffix: InkWell(child: const Icon(Icons.close, color: Color(0xffc8d6e5), size: 14,), onTap: (){
                       controller.clear();
                       FocusScope.of(context).requestFocus(FocusNode());
                    },),
                  ),
                )),
              ],
            ),
            Expanded(child:SingleChildScrollView(
              physics: const BouncingScrollPhysics(),
            child: Column(
                children: [
                  ...List.generate(10, (index) => const Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          SizedBox(height: 4,),
                          Text("龙阳花苑",),
                          Text("1.5km | 浦东新区东三里桥245弄", style: TextStyle(fontSize: 12, color: Colors.grey)),
                        ],
                      ),
                      Icon(Icons.check)
                    ],
                  ))
                ],
              ),
            )
            )
          ],
        ),
      );
  }
}
